package com.example.blogdemo.configuration;

import com.example.blogdemo.interceptor.ArticleClickInterceptor;
import com.example.blogdemo.interceptor.CreateRequestInterceptor;
import com.example.blogdemo.interceptor.PassportInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @Author Anita
 * @Date 2017/12/13 14:48
 */
@Configuration
public class WebSecurtiyConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private PassportInterceptor passportInterceptor;

    @Autowired
    private ArticleClickInterceptor articleClickInterceptor;

    @Autowired
    private CreateRequestInterceptor createRequestInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        InterceptorRegistration addInterceptor = registry.addInterceptor(passportInterceptor);
        addInterceptor.excludePathPatterns("/in","/login","/logout","/register");
        InterceptorRegistration addClickInterceptor = registry.addInterceptor(articleClickInterceptor);
        addClickInterceptor.addPathPatterns("/article/*");
        InterceptorRegistration addcreateRequestInterceptor = registry.addInterceptor(createRequestInterceptor);
        addcreateRequestInterceptor.addPathPatterns("/create");
    }
}
